package com.ai.controller;

import groovy.util.logging.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;

/**
 * @Author liuyjy
 * @Date 2025/2/18 11:04
 * @Description: https://mp.weixin.qq.com/s/LUct3F8tbH1tfmwSTr8o8w
 **/
@RestController
@CrossOrigin(origins = "*")
@Slf4j
@RequestMapping("/ai")
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);
    private final ChatClient chatClient;

    public TestController(ChatClient.Builder builder) {
//        this.chatClient = builder.defaultSystem("你是一个天气预报员，当有人输入日期的时候，你输出苏州的天气预报信息，" +
//                "生成结果在html页面中以markdown的格式输出，最后输出结尾的时候始终以下面的语句结尾：感谢您的咨询，我是舆情君。").build();
        this.chatClient = builder.defaultSystem("你是一个万能解答员,解答输入的问题，" +
                "生成结果在html页面中以markdown的格式输出").build();
    }

    //http://localhost:20020/ai/chat/2025%E5%B9%B42%E6%9C%8812%E6%97%A5
    @GetMapping(value = "/chat/{message}")
    public String chat(@PathVariable("message") String message) {
        log.info("message:{}", message);
        return chatClient.prompt()
                .user(message)
                .call()
                .content();
    }


}
